home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / thor / autoreply.br < prev    next >
Text File  |  1996-11-10  |  6KB  |  169 lines

  1. /* $VER: AutoReply.br 1.0 (30.07.96) Neil Bothwick */
  2. /* A Thor script to generate an event in reply to  */
  3. /* an email. It should be called from SortMail3    */
  4.  
  5. Usage = 'Usage: AutoReply.br Config MessageNo'
  6. options results
  7.  
  8. /* Strip "'s from arg string and parse into variables */
  9. drop Config.
  10. parse arg CmdLine
  11. CmdLine = compress(CmdLine,'"')
  12. parse var CmdLine Config.Name MsgNum
  13. if Config.Name = '?' | MsgNum = '' then call ExitMsg(Usage)
  14.  
  15. /* Load bbsread.library if necessary */
  16. if ~show('p', 'BBSREAD') then do
  17.     address command
  18.     'run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead'
  19.     'WaitForPort BBSREAD'
  20.     end
  21.  
  22. /* Open config file and find matching config entry */
  23. if ~open(cfgfile,'ENV:Thor/AutoReply.cfg','r') then call ExitMsg('Failed to open configuration file')
  24. do until eof(cfgfile) | ConfigFound = 'TRUE'
  25.     nextline = readln(cfgfile)
  26.     parse var nextline CfgName CfgVal .
  27.     CfgVal = compress(CfgVal,'"')
  28.     if upper(CfgName) = 'CONFIG' & upper(CfgVal) = upper(Config.Name) then ConfigFound = 'TRUE'
  29.     end
  30.  
  31. if eof(cfgfile) then call ExitMsg('Configuration entry for' Config.Name 'not found')
  32.  
  33. /* Read configuration details */
  34. n = 0
  35. do until eof(cfgfile)
  36.     nextline = readln(cfgfile)
  37.     parse var nextline CfgName '"' CfgVal '"' .
  38.     CfgVal = compress(CfgVal,'"')
  39.     if upper(CfgName) = 'ENDCONFIG' then leave
  40.     n = n+1
  41.     Config.n.Name = upper(CfgName)
  42.     Config.n.Val  = CfgVal
  43.     end
  44.  
  45. Config.Count = n
  46.  
  47. do i = 1 to Config.Count
  48.     select
  49.         when Config.i.Name = 'SYSTEM'     then Config.System   = Config.i.Val
  50.         when Config.i.Name = 'CONFERENCE' then Config.MailConf = Config.i.Val
  51.         when Config.i.Name = 'SUBJECT'    then Config.Subject  = Config.i.Val
  52.         when Config.i.Name = 'QUOTEMSG'   then Config.QuoteMsg = Config.i.Val
  53.         when Config.i.Name = 'QUOTESTR'   then Config.QuoteStr = Config.i.Val
  54.         when Config.i.Name = 'SIGFILE'    then Config.SigFile  = Config.i.Val
  55.         when Config.i.Name = 'HEADFILE'   then Config.HeadFile = Config.i.Val
  56.         when Config.i.Name = 'TEXTFILE'   then Config.TextFile = Config.i.Val
  57.         when Config.i.Name = 'FOOTFILE'   then Config.FootFile = Config.i.Val
  58.         otherwise call ExitMsg('Configuration file error')
  59.         end
  60.     end
  61.  
  62. if symbol('Config.System')    ~= 'VAR' then call ExitMsg('System name not defined in config')
  63. if symbol('Config.MailConf')  ~= 'VAR' then call ExitMsg('Mail conference not defined in config')
  64. if symbol('Config.TextFile')  ~= 'VAR' then call ExitMsg('Reply text not defined in config')
  65. if symbol('Config.QuoteStr') ~= 'VAR' then Config.QuoteStr = ''
  66.  
  67. /* Read incoming message */
  68. address BBSREAD
  69. drop MsgBody. MsgHead.
  70. READBRMESSAGE bbsname '"'Config.System'"' confname '"'Config.MailConf'"' msgnr MsgNum textstem MsgBody headstem MsgHead
  71. if RC > 0 then callExitMsg(BBSREAD.LASTERROR)
  72.  
  73. /* Create message file for reply */
  74. UNIQUEMSGFILE bbsname '"'Config.System'"' stem MsgFile
  75. if ~open(out,MsgFile.NAME,'w') then call ExitMsg('Unable to create message file')
  76.  
  77. /* write headers */
  78. if symbol('Config.HeadFile') = 'VAR' '' & exists(Config.HeadFile) then do
  79.     if ~open(headers,Config.HeadFile,'R') then call ExitMsg('Unable to open specified header file')
  80.     do until eof(headers)
  81.         headline = readln(headers)
  82.         call writeln(out,headline)
  83.         end
  84.     if headline > '' then call writeln(out,'')
  85.     call close(headers)
  86.     end
  87.  
  88. /* Quote original message above reply */
  89. if upper(Config.QuoteMsg) = 'ABOVE' then do
  90. do i = 1 to MsgBody.TEXT.COUNT
  91.     if length(MsgBody.TEXT.i) > 0 then call writeln(out,Config.QuoteStr||MsgBody.TEXT.i)
  92.     else call writeln(out,'')
  93.     end
  94. end
  95.  
  96. /* Write reply */
  97. if ~open(reply,Config.TextFile) then call ExitMsg('Unable to open reply text file')
  98. do until eof(reply)
  99.     call writeln(out,readln(reply))
  100.     end
  101. call close(reply)
  102.  
  103. /* Quote original message below reply */
  104. if upper(Config.QuoteMsg) = 'BELOW' then do i = 1 to MsgBody.TEXT.COUNT
  105.     if length(MsgBody.TEXT.i) > 0 then call writeln(out,Config.QuoteStr||MsgBody.TEXT.i)
  106.     else call writeln(out,'')
  107.     end
  108.  
  109. /* Add signature */
  110. if symbol('Config.SigFile') = 'VAR' '' & exists(Config.SigFile) then do
  111.     if ~open(sig,Config.SigFile,'R') then call ExitMsg('Unable to open signature file')
  112.     do until eof(sig)
  113.         sigline = readln(sig)
  114.         call writeln(out,sigline)
  115.         end
  116.     call close(sig)
  117.     end
  118.  
  119. /* Add footer file */
  120. if symbol('Config.FootFile') = 'VAR' '' & exists(Config.FootFile) then do
  121.     if ~open(foot,Config.FootFile,'R') then call ExitMsg('Unable to open footer file')
  122.     do until eof(foot)
  123.         footline = readln(foot)
  124.         call writeln(out,footline)
  125.         end
  126.     call close(foot)
  127.     end
  128.  
  129. call close(out)
  130.  
  131. /* Create subject line */
  132. ReplySubject = MsgHead.SUBJECT
  133. select
  134.     when symbol('Config.Subject') ~= 'VAR' then do
  135.         if left(upper(ReplySubject),3) ~= 'RE:' then ReplySubject = 'Re:' ReplySubject
  136.         end
  137.     when pos('%S',upper(Config.Subject)) = 0 then ReplySubject = Config.Subject
  138.     otherwise do
  139.         InsertPos = pos('%S',upper(Config.Subject))
  140.         ReplySubject = left(Config.Subject,InsertPos-1)||ReplySubject||substr(Config.Subject,InsertPos+2)
  141.         end
  142.     end
  143.  
  144. /* Create EMail reply event */
  145. drop EventData.
  146. EventData.TOADDR     = MsgHead.FROMADDR
  147. EventData.SUBJECT    = ReplySubject
  148. EventData.CONFERENCE = Config.MailConf
  149. EventData.MSGFILE    = MsgFile.FILEPART
  150. if symbol('MsgHead.FROMNAME') = 'VAR' then EventData.TONAME = MsgHead.FROMNAME
  151.  
  152. WRITEBREVENT bbsname '"'Config.System'"' event 0 stem EventData
  153. if RC > 0 then call ExitMsg(BBSREAD.LASTERROR)
  154.  
  155. exit
  156.  
  157.  
  158. ExitMsg:
  159.     parse arg msgstr
  160.     if symbol('MsgFile.NAME') = 'VAR' then do
  161.         call close(out)
  162.         address command 'delete >NIL:' MsgFile.NAME
  163.         end
  164.     say ''
  165.     say 'AutoReply.br:' msgstr
  166.     say ''
  167.     exit
  168.  
  169.